﻿//-----------------------------------------------------------------------
// <copyright file="IIdentityDataContractUnitTest.cs" company="CodePlex">
//     Copyright (c) Doug Holland, CodePlex. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
namespace CodePlex.Diagnostics.Contracts
{
    using System;
    using System.Security;
    using System.Security.Principal;
    
    using Microsoft.VisualStudio.TestTools.UnitTesting;

    /// <summary>
    /// Provides unit tests for the <see cref="T:CodePlex.Diagnostics.Contracts.IIdentityDataContract"/> class.
    /// </summary>
    [TestClass]
    public sealed class IIdentityDataContractUnitTest
    {
        #region public IIdentityDataContractUnitTest()

        /// <summary>
        /// Initializes a new instance of the <see cref="T:IIdentityDataContractUnitTest"/> class.
        /// </summary>
        public IIdentityDataContractUnitTest()
        {
        }

        #endregion

        #region public TestContext TestContext

        /// <summary>
        /// Gets or sets the test context which provides information about and functionality for the current test run.
        /// </summary>
        public TestContext TestContext
        {
            get;
            set;
        }

        #endregion

        #region public void IIdentityDataContractConstructorUnitTest()

        /// <summary>
        /// Ensures that the constructor of the <see cref="T:CodePlex.Diagnostics.Contracts.IIdentityDataContract"/> class is correctly copying the values from the supplied <see cref="T:System.Security.Principal.IIdentity"/> instance.
        /// </summary>
        [TestMethod]
        public void IIdentityDataContractConstructorUnitTest()
        {
            IIdentity windowsIdentity = WindowsIdentity.GetCurrent() as IIdentity;
        
            IIdentityDataContract identity = new IIdentityDataContract(windowsIdentity);

            Assert.IsFalse(string.IsNullOrEmpty(identity.SerializedIIdentity), "data contract contains an invalid soap encoded identity instance.");

            Assert.IsNotNull(identity.DeserializedIdentity, "an error occurred deserializing the soap encoded identity instance.");

            Assert.AreEqual<string>(windowsIdentity.AuthenticationType, identity.AuthenticationType, "data contract contains an invalid authentication type value.");
            
            Assert.AreEqual<bool>(windowsIdentity.IsAuthenticated, identity.IsAuthenticated, "data contract contains an invalid value indicating whether the user is authenticated or not.");
            
            Assert.AreEqual<string>(windowsIdentity.Name, identity.Name, "data contract contains an invalid name value.");        
        }
        
        #endregion
    }
}
